package com.appspot.bs24event.controller.event.attendance;

import org.slim3.controller.BaseController;
import org.slim3.controller.Navigation;
import org.slim3.util.RequestMap;

import com.appspot.bs24event.service.AttendanceService;

public class RegisterController extends BaseController {

    private AttendanceService service = new AttendanceService();

    @Override
    protected Navigation setUp() {
        logger.info(this.getClass().getName() + " start.");
        return super.setUp();
    }

    @Override
    protected void tearDown() {
        logger.info(this.getClass().getName() + " end.");
        super.tearDown();
    }

    @Override
    public Navigation run() throws Exception {

        return doPost();
    }


    private Navigation doPost() {

        RequestMap requestMap = new RequestMap(request);
        requestMap.put("eventKey", asKey("key"));
        requestMap.remove("key");
        requestMap.put("eventVersion", asLong("version"));
        requestMap.remove("version");
        service.insert(requestMap);

        return redirect("/event/attendance/detail?key="+ request.getParameter("key") + "&version=" + request.getParameter("version"));
    }
}
